String.prototype.replaceAll = function (FindText, RepText) {
    regExp = new RegExp(FindText, "g");
    return this.replace(regExp, RepText);
}

function strtotime(str) {
    var arr = str.split(/[- : \/]/);
    var date = new Date(arr[0], arr[1] - 1, arr[2], arr[3], arr[4], arr[5]);
    // date = new Date(str);苹果不兼容
    return Date.parse(date) / 1000;
}

function drawing(e) {
    clearInterval(app.timer);
    $("#" + e).find(".cai-num").html('<img src="/public/static/images/load3.gif" alt="开奖中"/><img src="/public/static/images/load3.gif" alt="开奖中"/><img src="/public/static/images/load3.gif" alt="开奖中"/>');
    $("#" + e).find(".djs").html("开奖中");
}

function countdown(e) {
    $("#" + e).find(".djs").html(format_time(app.ticking, "开奖中"));
    clearInterval(app.timer);
    app.timer = setInterval(function () {
        if (--app.ticking < 0)
            return clearInterval(app.timer),
                void loadplan();
        $("#" + e).find(".djs").html(format_time(app.ticking, "开奖中"));
        app.element.progress('dsjjdt', (app.progress - app.ticking) / app.progress * 100 + '%')
    }, 1000)
}

function format_time(t, e) {
    var a = parseFloat(t)
        , n = 0
        , s = 0
        , d = 0
        , r = "<em>分</em>"
        , i = "</span>";
    return null != a && "" != a && (a < 60 ? (d = a,
        a = "<span>00</span>" + r + "<span>" + (d > 9 ? d : "0" + d) + i + "<em>秒</em>") : a >= 60 && a < 3600 ? (s = parseInt(a / 60),
        d = parseInt(a % 60),
        a = "<span>" + (s > 9 ? s : "0" + s) + i + r + "<span>" + (d > 9 ? d : "0" + d) + i + "<em>秒</em>") : a >= 3600 && (n = parseInt(a / 3600),
        s = parseInt(a % 3600 / 60),
        d = parseInt(a % 3600 % 60 % 60),
        a = "<span>" + (n > 9 ? n : "0" + n) + i + "<em>时</em><span>" + (s > 9 ? s : "0" + s) + i + r)),
        0 == a && e ? e : a
}

function toPlanStr(plans) {
    var planStr = "";
    $.each(plans, function (i, n) {
        if (i > 0) {
            planStr += " ";
        }
        planStr += n;
    });
    return planStr;
}

function calculateMultiple(plan, planList, openhis) {
    if (plan.win === true || plan.win === false)
        return 0;
    var lastWinIssue = plan.beginIssue;
    $.each(planList, function (i, n) {
        if (n.win === true) {
            lastWinIssue = n.winIssue;
            return false;
        }
        else if (n.win === false) {
            lastWinIssue = n.beginIssue;
        }
    });
    var n = plan.winIssue - lastWinIssue;
    for (n = 0; n < openhis.length && openhis[n].issue != lastWinIssue; n++) ;
    var arr = [1, 3, 9, 27, 81, 243, 243 * 3, 243 * 3 * 3];
    if (n >= arr.length)
        n = arr.length - 1;
    else if (n < 0)
        n = 0;
    return arr[n];
}

$(function () {
    setTimeout("$('.couponGuide').hide()", 5000);

    $("#ppchat-plans li:eq(0)").addClass('layui-this');
    $("#show-did-" + app.did).addClass('layui-show');
    $("#ppchat-plans li").click(function () {
        $("#ppchat-plans li").removeClass('layui-this');
        $(this).addClass('layui-this')
        app.cplan = "";
        $("#show-did-" + app.did).removeClass('layui-show');
        app.did = $(this).data('did');
        $("#show-did-" + app.did).addClass('layui-show');
        $(".current").html('');
    });

    $("#videoBtn").on("click", function () {
        $(".shade").show();
        $(".videoDiv").show();
        $(".videoDiv").html('<iframe src="' + $(".videoDiv").attr("video-src") + '" width="100%"></iframe>');
    });
    $(".shade").on("click", function () {
        $(".shade").hide();
        $(".videoDiv").hide();
        $(".videoDiv").html("");
    });
});
layui.use(['carousel', 'element'], function () {

    var carousel = layui.carousel;
    carousel.render({
        elem: '#ads'
        , width: '100%' //设置容器宽度
        , arrow: 'hover' //始终显示箭头
        , height: layui.$("#ads").width() * (1 / 5)
        , interval: 6000
    });
    app.element = layui.element;
    loadplan();
});